<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0">

		<title>地址管理</title>

		<link href="/Public/AmazeUI-2.4.2/assets/css/admin.css" rel="stylesheet" type="text/css">
		<link href="/Public/AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css">

		<link href="/Public/css/personal.css" rel="stylesheet" type="text/css">
		<link href="/Public/css/addstyle.css" rel="stylesheet" type="text/css">
		<script src="/Public/AmazeUI-2.4.2/assets/js/jquery.min.js" type="text/javascript"></script>
		<script src="/Public/AmazeUI-2.4.2/assets/js/amazeui.js"></script>
		<link type="text/css" rel="stylesheet" href="/Public/select3/css/demo.css">
		<link type="text/css" rel="stylesheet" href="/Public/select3/css/layout.css">
	</head>

	<body>
		<!--头 -->
		<header>
			<article>
				<div class="mt-logo">
					<!--顶部导航条 -->
					<include file='./Application/Home/View/Share/header.html'/>
				</div>
			</article>
		</header>

		<div class="nav-table">
			<div class="long-title"><span class="all-goods">全部分类</span></div>
			<div class="nav-cont">
				<ul>
					<li class="index"><a href="#">首页</a></li>
					<li class="qc"><a href="#">闪购</a></li>
					<li class="qc"><a href="#">限时抢</a></li>
					<li class="qc"><a href="#">团购</a></li>
					<li class="qc last"><a href="#">大包装</a></li>
				</ul>
				<div class="nav-extra">
					<i class="am-icon-user-secret am-icon-md nav-user"></i><b></b>我的福利
					<i class="am-icon-angle-right" style="padding-left: 10px;"></i>
				</div>
			</div>
		</div>
		<b class="line"></b>

		<div class="center">
			<div class="col-main">
				<div class="main-wrap">

					<div class="user-address">
						<!--标题 -->
						<div class="am-cf am-padding">
							<div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">地址管理</strong> / <small>Address&nbsp;list</small></div>
						</div>
						<hr/>
						<ul class="am-avg-sm-1 am-avg-md-3 am-thumbnails" id="showaddr">
							<li class="user-addresslist">暂无收货地址</li>
							<!-----显示已存在的收货地址----->
						</ul>
						<div class="clear"></div>
						<a class="new-abtn-type" data-am-modal="{target: '#doc-modal-1', closeViaDimmer: 0}">添加新地址</a>
						<!--例子-->
						<div class="am-modal am-modal-no-btn" id="doc-modal-1">

							<div class="add-dress">

								<!--标题 -->
								<div class="am-cf am-padding">
									<div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">新增地址</strong> / <small>Add&nbsp;address</small></div>
								</div>
								<hr/>

								<div class="am-u-md-12 am-u-lg-8" style="margin-top: 20px;" >
									<form class="am-form am-form-horizontal">
			<div class="am-form-group">
				<label for="user-name" class="am-form-label">收货人</label>
				<div class="am-form-content">
					<input type="text" id="user_nickname" placeholder="收货人">
				</div>
			</div>

			<div class="am-form-group">
				<label for="user-phone" class="am-form-label">手机号码</label>
				<div class="am-form-content">
					<input id="mobile_no" placeholder="手机号必填" type="text">
				</div>
			</div>
			<div class="am-form-group">
				<label for="user-address" class="am-form-label">所在地</label>
				<div class="am-form-content address" id="city_china">
							
						<select class="province cxselect" disabled="disabled" id="province" name="province"></select>
						<select class="city cxselect" disabled="disabled" id="city" name="city"></select>
						<select class="area cxselect" disabled="disabled" id="area" name="area"></select>
				
				</div>
			</div>

			<div class="am-form-group">
				<label for="user-intro" class="am-form-label">详细地址</label>
				<div class="am-form-content">
					<textarea class="" rows="3" id="addr" placeholder="输入详细地址"></textarea>
					<small>100字以内写出你的详细地址/Public.</small>
				</div>
			</div>

			<div class="am-form-group">
				<div class="am-u-sm-9 am-u-sm-push-3">
					<a class="am-btn am-btn-danger" onclick="newaddr();">保存</a>
					<a href="javascript: void(0)" class="am-close am-btn am-btn-danger" data-am-modal-close>取消</a>
				</div>
			</div>
		</form>	
								</div>

							</div>

						</div>

					</div>

					

					<div class="clear"></div>

				</div>
				<!--底部-->
				<include file='./Application/Home/View/Share/footer.html'/>
			</div>

			<aside class="menu">
				<ul>
					<li class="person">
						<a href="index.html">个人中心</a>
					</li>
					<li class="person">
						<a href="#">个人资料</a>
						<ul>
							<li> <a href="information.html">个人信息</a></li>
							<li> <a href="safety.html">安全设置</a></li>
							<li class="active"> <a href="address.html">收货地址</a></li>
						</ul>
					</li>
					<li class="person">
						<a href="#">我的交易</a>
						<ul>
							<li><a href="order.html">订单管理</a></li>
							<li> <a href="change.html">退款售后</a></li>
						</ul>
					</li>
					<li class="person">
						<a href="#">我的资产</a>
						<ul>
							<li> <a href="coupon.html">优惠券 </a></li>
							<li> <a href="bonus.html">红包</a></li>
							<li> <a href="bill.html">账单明细</a></li>
						</ul>
					</li>

					<li class="person">
						<a href="#">我的小窝</a>
						<ul>
							<li> <a href="collection.html">收藏</a></li>
							<li> <a href="foot.html">足迹</a></li>
							<li> <a href="comment.html">评价</a></li>
							<li> <a href="news.html">消息</a></li>
						</ul>
					</li>

				</ul>

			</aside>
		</div>

	</body>
<!-------编辑新增地址----->	
<script id="showaddr-tpl" type="text/html">
	<% for ( i = 0; i < data.length; i++){%>
		<li class="user-addresslist">
			<span class="new-option-r" onclick="moren(<%=data[i].addr_id%>)" id="a<%=data[i].status%>"><i class="am-icon-check-circle"></i>默认地址</span>
			<p class="new-tit new-p-re">
				<span class="new-txt"><%=data[i].user_nickname%></span>
				<span class="new-txt-rd2"><%=data[i].mobile_no%></span>
			</p>
			<div class="new-mu_l2a new-p-re">
				<p class="new-mu_l2cw">
					<span class="title">地址：</span>
					<span class="province"><%=data[i].province%></span>
					<span class="city"><%=data[i].city%></span>
					<span class="dist"><%=data[i].area%></span>
					<span class="street"><%=data[i].addr%></span></p>
			</div>
			<div class="new-addr-btn">
				<a href="/Home/Person/bjAddress?addr_id=<%=data[i].addr_id%>"><i class="am-icon-edit"></i>编辑</a>
				<span class="new-addr-bar">|</span>
				<a href="javascript:void(0);" onclick="delClick(<%=data[i].addr_id%>);"><i class="am-icon-trash"></i>删除</a>
			</div>
		</li>
	<%}%>
	<script type="text/javascript">
		$(document).ready(function() {							
			//$(".new-option-r").click(function() {
				//$(this).parent('.user-addresslist').addClass("defaultAddr").siblings().removeClass("defaultAddr");
			//});	
			var $ww = $(window).width();
			if($ww>640) {
				$("#doc-modal-1").removeClass("am-modal am-modal-no-btn")
			}		
		})
	</script>						
</script>
		
</html>
<script src="/Public/select3/js/jquery-1.7.2.min.js"></script>
<script src="/Public/select3/js/jquery.cxselect.min.js"></script>
<script>
$.cxSelect.defaults.url = '/Public/select3/js/cityData.min.json';

$('#city_china').cxSelect({
	selects: ['province', 'city', 'area']
});

$('#city_china_val').cxSelect({
	selects: ['province', 'city', 'area'],
	nodata: 'none'
});
function newaddr(){
	var user_nickname = $('#user_nickname').val();
	var mobile_no = $('#mobile_no').val();
	var province = $('#province').val();
	var city = $('#city').val();
	var area = $('#area').val();
	var addr = $('#addr').val();
	$.get('/Api/Person/newaddr',{user_nickname:user_nickname,mobile_no:mobile_no,province:province,city:city,area:area,addr:addr},function(ret){
		if(ret.staus == true ){
			
			alert("添加成功！");
			window.location.href=window.location.href;
		}else{
			alert("添加失败！");
		}
	});	
}

function show(){
	$.get('/Api/Person/show',null,function(ret){
		if(ret.staus == true ){
			var html = template('showaddr-tpl',ret);
			$('#showaddr').html(html);
		}else{
			alert("未知错误");
		}
	});		
}
show();
function moren(obj){
	$.get('/Api/Person/moren',{addr_id:obj},function(ret){
		if(ret.staus == true ){
			window.location.reload();
		}else{
			alert("未知错误");
		}
	});	
}
function showmoren(){	
	$.get('/Api/Person/showmoren',null,function(ret){
		$('#a1').parent('.user-addresslist').addClass("defaultAddr");
		if(ret.staus == true ){
			$('#a1').parent('.user-addresslist').addClass("defaultAddr").siblings().removeClass("defaultAddr");
		}else{
			alert("未知错误");
		}
	});	
}
showmoren();
function delClick(obj){
	var conf=window.confirm("确认删除");
	if(conf==true){
		$.get('/Api/Person/delClick',{addr_id:obj},function(ret){
			if(ret.staus == true ){
				alert("删除成功");
				show();
			}else{
				alert("未知错误");
			}
		});	
	}
}
</script>
